package com.ljf.game.event;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONException;

import java.io.Serializable;

/**
 * 说明：
 *
 * @Auther: lijinfeng
 * @Date: 2023/11/9
 *
 * ｛
 *    "EVENT_CLASS":"CREATE_ROOM"
 * ｝
 */
public class Event implements Serializable {
   /**
    * 报文内容
    */
   private String text;


   public String getText() {
      return text;
   }

   public void setText(String text) {
      this.text = text;
   }


   /**
    * 转成对象
    *
    * @param text text
    * @return Event
    */
   public static <T extends Event> T toEvent(String text, Class<T> clazz) {
      T event = null;
      try {
         event = JSON.parseObject(text, clazz);
      } catch (JSONException e) {
         System.out.println(e.getMessage() + ":" + text);
      }

      event.setText(text);
      return event;
   }

}
